package com.kyzh.core.activities

import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import com.gushenge.core.base.activity.BaseActivity
import com.kyzh.core.R
import com.kyzh.core.adapters.CollectionTabAdapter
import com.kyzh.core.utils.dip
import kotlinx.android.synthetic.main.activity_collection.*
import kotlinx.android.synthetic.main.titlebar.*

class CollectionActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_collection)
        initView()
    }

    private fun initView() {
        (tabLayout.background as GradientDrawable).cornerRadius = dip(12).toFloat()
        close.setOnClickListener { finish() }
        tvTitle.text = getString(R.string.myCollect)
        tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabReselected(tab: TabLayout.Tab?) {
                viewPager.currentItem = tab?.position?:0
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {

            }

            override fun onTabSelected(tab: TabLayout.Tab?) {
                viewPager.currentItem = tab?.position?:0
            }
        })

        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {
                tabLayout.selectTab(tabLayout.getTabAt(position))
            }
        })

        viewPager.currentItem = 0
        viewPager.adapter = CollectionTabAdapter(this@CollectionActivity)
    }
}
